package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCompanyFile;
import com.ruoyi.system.service.ISysCompanyFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业诊断文件Controller
 * 
 * @author ruoyi
 * @date 2023-06-14
 */
@Api(tags = "企业诊断文件")
@RestController
@RequestMapping("/system/file")
public class SysCompanyFileController extends BaseController
{
    @Autowired
    private ISysCompanyFileService sysCompanyFileService;

    /**
     * 查询企业诊断文件列表
     */
    @ApiOperation(value = "查询企业诊断文件列表")
   // @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public AjaxResult list(SysCompanyFile sysCompanyFile)
    {

        List<SysCompanyFile> list = sysCompanyFileService.selectSysCompanyFileList(sysCompanyFile);
        return AjaxResult.success(list);

    }

    /**
     * 导出企业诊断文件列表
     */
    @ApiOperation(value = "导出企业诊断文件列表")
   // @PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "企业诊断文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCompanyFile sysCompanyFile)
    {
        List<SysCompanyFile> list = sysCompanyFileService.selectSysCompanyFileList(sysCompanyFile);
        ExcelUtil<SysCompanyFile> util = new ExcelUtil<SysCompanyFile>(SysCompanyFile.class);
        util.exportExcel(response, list, "企业诊断文件数据");
    }

    /**
     * 获取企业诊断文件详细信息
     */
    @ApiOperation(value = "获取企业诊断文件详细信息")
   // @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return AjaxResult.success(sysCompanyFileService.selectSysCompanyFileByFileId(fileId));
    }

    /**
     * 提交企业诊断文件
     */
    @ApiOperation(value = "提交企业诊断文件")
  //  @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "企业诊断文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCompanyFile sysCompanyFile)
    {
        return toAjax(sysCompanyFileService.insertSysCompanyFile(sysCompanyFile));
    }

    /**
     * 审核企业诊断文件
     */
    @ApiOperation(value = "审核企业诊断文件")
  //  @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "企业诊断文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCompanyFile sysCompanyFile)
    {
        sysCompanyFile.setCheckor(getUsername());
        return toAjax(sysCompanyFileService.updateSysCompanyFile(sysCompanyFile));
    }

    /**
     * 退回重新提交企业诊断文件
     */
    @ApiOperation(value = "退回重新提交企业诊断文件")
    //  @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "企业诊断文件", businessType = BusinessType.UPDATE)
    @PutMapping("/again")
    public AjaxResult updateAgainSysCompanyFile(@RequestBody SysCompanyFile sysCompanyFile)
    {
        return toAjax(sysCompanyFileService.updateAgainSysCompanyFile(sysCompanyFile));
    }

    /**
     * 删除企业诊断文件
     */
    @ApiOperation(value = "删除企业诊断文件")
  //  @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "企业诊断文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(sysCompanyFileService.deleteSysCompanyFileByFileIds(fileIds));
    }

}
